import request from '@jsrequest'

export function addPersonnel(params) {
  return request({
    url: '/setting/add/personnel',
    method: 'post',
    data: params,
    transformRequest: [function(data) {
      const formData = new FormData()
      for (const key of Object.keys(data)) {
        formData.append(key, data[key])
      }
      return formData
    }]
  })
}

export function modifyPersonnel(params) {
  return request({
    url: '/setting/modify/personnel',
    method: 'POST',
    data: params,
    transformRequest: [function(data) {
      const formData = new FormData()
      for (const key of Object.keys(data)) {
          formData.append(key, data[key])
      }
      return formData
    }]
  })
}

export function getUserList(params) {
  return request({
    url: '/setting/query/user_table',
    method: 'get',
    params
  })
}

export function getAccountList(params) {
  return request({
    url: '/setting/type/obtain/account/list',
    method: 'get',
    params
  })
}

export function getAccountBodyList(id) {
  return request({
    url: '/setting/type/obtain/account/body',
    method: 'post',
    params: { id }
  })
}

export function modifyAccountRate(data) {
  return request({
    url: '/setting/type/modify/account_rate',
    method: 'post',
    data,
    transformRequest: [function(data) {
      let formData
      if (!data) {
        formData = data
      } else {
        formData = new FormData()
      for (const key of Object.keys(data)) {
        formData.append(key, data[key])
      }
      }
      return formData
    }]
  })
}

export const locGetAccountBodyList = {
    'status': 0,
    'msg': 'SUCCESS',
    'result': {
        'rateBody': {
            'dally': [
                {
                    'id': 4,
                    'rateAndSport': [
                        {
                            'rate': 0.12,
                            'sport': 73
                        },
                        {
                            'rate': 0.91,
                            'sport': 74
                        },
                        {
                            'rate': 0.314,
                            'sport': 75
                        },
                        {
                            'rate': 0.16,
                            'sport': 115
                        },
                        {
                            'rate': 0.66,
                            'sport': 116
                        },
                        {
                            'rate': 0.33,
                            'sport': 117
                        }
                    ],
                    'title': 57,
                    'titleName': 'Blood'
                }
            ],
            'halfDay': [
                {
                    'id': 5,
                    'rateAndSport': [
                        {
                            'rate': 0.78,
                            'sport': 73
                        },
                        {
                            'rate': 0.191,
                            'sport': 74
                        },
                        {
                            'rate': 0.334,
                            'sport': 75
                        },
                        {
                            'rate': 0.16,
                            'sport': 115
                        },
                        {
                            'rate': 0.66,
                            'sport': 116
                        },
                        {
                            'rate': 0.343,
                            'sport': 117
                        }
                    ],
                    'title': 58,
                    'titleName': 'Urine   Blood'
                }
            ],
            'hourly': [
                {
                    'id': 2,
                    'rateAndSport': [
                        {
                            'rate': 0.5738,
                            'sport': 73
                        },
                        {
                            'rate': 0.491,
                            'sport': 74
                        },
                        {
                            'rate': 0.134,
                            'sport': 75
                        },
                        {
                            'rate': 0.16,
                            'sport': 115
                        },
                        {
                            'rate': 0.366,
                            'sport': 116
                        },
                        {
                            'rate': 0.313,
                            'sport': 117
                        }
                    ],
                    'title': 76,
                    'titleName': 'Arm'
                }
            ],
            'session': [
                {
                    'id': 3,
                    'rateAndSport': [
                        {
                            'rate': 0.178,
                            'sport': 73
                        },
                        {
                            'rate': 0.91,
                            'sport': 74
                        },
                        {
                            'rate': 0.34,
                            'sport': 75
                        },
                        {
                            'rate': 0.516,
                            'sport': 115
                        },
                        {
                            'rate': 0.166,
                            'sport': 116
                        },
                        {
                            'rate': 0.33,
                            'sport': 117
                        }
                    ],
                    'title': 56,
                    'titleName': 'Urine'
                }
            ]
        },
        'titleName': [
            {
                'name': 'Archery',
                'sport': 73
            },
            {
                'name': 'Swimming',
                'sport': 74
            },
            {
                'name': 'Gun Shotting',
                'sport': 75
            },
            {
                'name': 'Tennis',
                'sport': 115
            },
            {
                'name': 'Basketball',
                'sport': 116
            },
            {
                'name': 'Table Tennis',
                'sport': 117
            }
        ]
    }
}
// 保存account的费率数据（注意这里的参数比较复杂）
export function saveRateBody(data) {
  return request({
    url: '/setting/type/handle/account',
    method: 'post',
    //headers: { 'Content-Type': 'application/json;charset=UTF-8' },
    data,
    _transformRequest:true
  })
}

export function getUserInfoid(params) {
  return request({
    url: '/setting/query/user_info_id',
    method: 'get',
    params,
  })
}

export function exportPersonnel(params) {
  return request({
    url: '/export/xls',
    method: 'get',
    params
  })
}

export function exportToken(params) {
  return request({
    url: '/setting/temporary/token',
    method: 'post',
    data: params,
    transformRequest: [function(data) {
      const formData = new FormData()
      for (const key of Object.keys(data)) {
        formData.append(key, data[key])
      }
      return formData
    }]
  })
}

export function queryAthletesList(params) {
  return request({
    url: '/setting/query/athletes',
    method: 'get',
    params
  })
}

export function queryUserList(params) {
  return request({
    url: '/setting/query/not_athletes',
    method: 'get',
    params
  })
}

export function getTypes(params) {
  return request({
    url: '/setting/type/query_code',
    method: 'get',
    params
  })
}
export function getBelongingTypes(params) {
  return request({
    url: '/setting/type/query',
    method: 'get',
    params
  })
}

export function addTypes(params) {
  return request({
    url: '/setting/type/add',
    method: 'post',
    params
  })
}
export function delTypes(params) {
  return request({
    url: '/setting/type/del',
    method: 'post',
    params
  })
}
export function modifyTypes(params) {
  return request({
    url: '/setting/type/modify',
    method: 'post',
    params
  })
}

export function upload(params) {
  return request({
    url: '/manager/file/upload',
    method: 'post',
    params
  })
}
